# frozen_string_literal: true

# class for tasks
class Order
  include Mongoid::Document
  include Mongoid::Timestamps
  include Db::Operations
  # paginates_per 10
  field :order_no, type: String
  field :user_id, type: String
  field :amt, type: Float
  field :status, type: Integer, default: 0 # 0: draft; 1:planned
  field :t_id, type: String, default: -> { id.to_s }
  field :deleted, type: Boolean, default: false
  field :is_mock, type: Boolean, default: false
  scope :valid, -> { where(deleted: false) }

  def self.broadcast(cpu, ram)
    redis = Redis.new
    data = { cpu_rate: cpu, ram_rate: ram }
    redis.publish(:broadcast, data.to_json)
  end
end
